﻿using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.CultureSwitcher.Models;
using Orchard.Data.Migration;

namespace Orchard.CultureSwitcher
{
    public class Migrations : DataMigrationImpl
    {
        public int Create()
        {
            ContentDefinitionManager.AlterPartDefinition(typeof(CultureSwitcherPart).Name, cfg => cfg.Attachable());

            ContentDefinitionManager.AlterTypeDefinition("CultureSwitcherWidget", cfg => cfg
                .WithPart("CultureSwitcherPart")
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithSetting("Stereotype", "Widget"));

            SchemaBuilder.CreateTable(
                "CulturesOrderRecord",
                table => table
                    .Column<int>("Id", col => col.PrimaryKey().Identity())
                    .Column<string>("Culture", col => col.Unique().NotNull())
                    .Column<int>("OrderNumber", col => col.NotNull())
                );
            
            return 1;
        }

        public int UpdateFrom1()
        {
            SchemaBuilder.CreateTable("SwitcherSettingsPartRecord", table =>
                table
                .ContentPartRecord()
                .Column<int>("DisplayMode")
                .Column<int>("DisplayType"));
            return 2;
        }
    }
}